﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.SQLServerDAL;
using Hangjing.Common;
using Hangjing.Model;

/// <summary>
/// 班次管理
/// </summary>
public partial class qy_54tss_Admin_activeindexlinklist_delivershiftslist : System.Web.UI.Page
{
    shopdelivery dal = new shopdelivery();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            getItem();
        }
    }

    protected void getItem()
    {
        int togoid = HjNetHelper.GetQueryInt("tid", 0);//商家id
        IList<shopdeliveryInfo> list = dal.GetListByTogoNum(togoid);
        rptsubItem.DataSource = list;
        rptsubItem.DataBind();
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            if (dal.DelList(e.CommandArgument.ToString()) > 0)
            {
                AlertScript.RegScript(this, UpdatePanel1, "jtip('删除成功！');init();");
                getItem();
            }
            else
            {
                AlertScript.RegScript(this, UpdatePanel1, "jtip('删除失败，请重试！');init();");
            }
        }
    }

    protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        rptsubItem.EditIndex = e.NewEditIndex;
        getItem();
    }

    protected void GridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        rptsubItem.EditIndex = -1;
        getItem();
    }

    protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int id = Convert.ToInt32(((Label)rptsubItem.Rows[e.RowIndex].FindControl("lb_id")).Text.Trim());

        Hangjing.Model.shopdeliveryInfo model = dal.GetModel(id);
        model.tid = HjNetHelper.GetQueryInt("tid", 0);
        model.distancestart = Convert.ToDecimal(((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tbdistancestart")).Text);
        model.distanceend = Convert.ToDecimal(((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tbdistanceend")).Text);
        model.minmoney = 0;
        model.sendmoney = Convert.ToDecimal(((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tbsendmoney")).Text);
        model.ReveVar2 = WebUtility.InputText(((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tbReveVar2")).Text);
        model.ReveVar1 = WebUtility.InputText(((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tbReveVar1")).Text);
        model.ReveInt2 = 0;
        model.ReveInt1 = 0;
        model.ReveFloat1 = Convert.ToDecimal(((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tbReveFloat1")).Text);
        model.ReveFloat2 = 0;

        if (dal.Update(model) > 0)
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('编辑成功！');init();");
            getItem();
        }
        else
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('编辑失败，请重试！');init();");
        }
        rptsubItem.EditIndex = -1;
        getItem();
    }

    protected void btSave_Click(object sender, EventArgs e)
    {

        Hangjing.Model.shopdeliveryInfo model = new shopdeliveryInfo();
        model.tid = HjNetHelper.GetQueryInt("tid", 0);
        model.distancestart = Convert.ToDecimal(WebUtility.InputText(this.tbdistancestart.Text));
        model.distanceend = Convert.ToDecimal(WebUtility.InputText(this.tbdistanceend.Text));
        model.minmoney = 0;
        model.sendmoney = Convert.ToDecimal(WebUtility.InputText(this.tbsendmoney.Text));
        model.ReveVar2 = WebUtility.InputText(this.tbReveVar2.Text);
        model.ReveVar1 = WebUtility.InputText(this.tbReveVar1.Text);
        model.ReveInt2 = 0;
        model.ReveInt1 = 0;
        model.ReveFloat1 = Convert.ToDecimal(WebUtility.InputText(this.tbReveFloat1.Text));
        model.ReveFloat2 = 0;

        model.AddTime = DateTime.Now;


        //判断权限
        int _rs = WebUtility.checkOperator(2);
        if (_rs == 0)
        {
            AlertScript.RegScript(this.Page, this.UpdatePanel1, "alert('无操作权限','success','true',5);init();");
            return;
        }
        dal.AddRule(model);

        AlertScript.RegScript(Page, UpdatePanel1, "jtip('操作成功！');init();");
        getItem();

    }
}

